package leoner.multithread4;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;

import leoner.multithread3.MethodInvokeInfoBean;

public class GetUrlCallable<T> implements Callable<T>{
	private MethodInvokeInfoBean methodInfo;
	public GetUrlCallable(Class returnType,String methodName,Object target,Object...parameters ){
		methodInfo = new MethodInvokeInfoBean(returnType,methodName,target,parameters);
	}
	@Override
	public T call() throws Exception {
		Object returnValue = null;
		try {
			Method method = methodInfo.getTargetObject().getClass().
				getMethod(methodInfo.getTargetMethodName(),methodInfo.getCls());
			
			returnValue = method.invoke(methodInfo.getTargetObject(), methodInfo.getParameters());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.printf( "%s done invoke result:\n", returnValue );
		return (T)returnValue;
	}
	
}
